package com.w7vm.menuweb.utility;


import java.util.Map;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import com.w7vm.menuweb.vo.*; 

@FacesConverter(value = "alimentosConverter", forClass = AlimentoVO.class)
public class AlimentosConverter implements Converter {
 
    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
        if (value != null && !value.isEmpty()) {
        	System.out.println("Converter getAsObject...."+ value);
            return (AlimentoVO) uiComponent.getAttributes().get(value);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
        if (value instanceof AlimentoVO) {
        	AlimentoVO entity= (AlimentoVO) value;
            if (entity != null && entity instanceof AlimentoVO && entity.getId() != null) {
                uiComponent.getAttributes().put( entity.getId().toString(), entity);
            	System.out.println("Converter getAsString...."+ entity.getId().toString());

                return entity.getId().toString();
            }
        }
        return "";
    }
 
}
